extends GridContainer

var rucksack_capcity=0
@onready var rucksack = $"."

# Called when the node enters the scene tree for the first time.
func _ready():
	Event.rucksack_add_big.connect(add_big)
	Event.rucksack_add_small.connect(add_small)
	Event.rucksack_add_bow.connect(add_bow)
	pass # Replace with functio     body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass
#物品编码：0、empty 1、small 2、big 3、bow

func add_small():
	var is_save=cacular_rucksack_save_gezi()
	if is_save!=-1:
		var SMALL = preload("res://sprite/small.tscn").instantiate()
		var gezi = rucksack.get_child(is_save)
		Event.rucksack_prop[is_save]=1
		is_save+=1		
		print(is_save)
		gezi.add_child(SMALL)
	else:
		pass
	
func add_big():
	var is_save=cacular_rucksack_save_gezi()
	if is_save!=-1:
		var BIG = preload("res://sprite/big.tscn").instantiate()
		var gezi = rucksack.get_child(is_save)
		Event.rucksack_prop[is_save]=2
		is_save+=1		
		print(is_save)
		gezi.add_child(BIG)
	else:
		pass
	
func add_bow():
	var is_save=cacular_rucksack_save_gezi()
	if is_save!=-1:
		var BOW = preload("res://sprite/bow.tscn").instantiate()
		var gezi = rucksack.get_child(is_save)
		Event.rucksack_prop[is_save]=3
		is_save+=1		
		print(is_save)
		gezi.add_child(BOW)
	else:
		pass
		

func cacular_rucksack_save_gezi():
	var i=0
	while Event.rucksack_prop[i]!=0:
		i+=1
	if i>=25:
		print("pack full!")
		return -1
	return i
